<script setup lang="ts">
import { useRoute, useRouter } from 'vue-router';
import { Api } from '@/assets/apis';
import { ref, onMounted } from 'vue'
import type { ListType } from '@/typings'


const ListType = ref<ListType>({} as ListType)
const router = useRouter()
const route = useRoute()
const id = ref()

const read = (id: string, secId: string) => {
    router.push(`/reader/book/${id}?uuid=${secId}`)
}

onMounted(async () => {
    id.value = route.params.id
    let { data } = await Api.getList(id.value)
    ListType.value = data
    // console.log('list', ListType.value);
})
</script>

<template>
    <div class="header">
        <div class="back" @click="router.go(-1)">
            <van-icon name="arrow-left" />
        </div>
        <div class="title">目录</div>
        <div class="home" @click="router.push('/')">首页</div>
    </div>
    <div class="directory-detail">
        <div class="item" v-for="a in ListType.data?.catalog" @click="read(id, a.secId)">
            {{ a.title }}
        </div>
    </div>
</template>

<style scoped lang="scss">
.header {
    width: 375rem;
    height: 44rem;
    background-color: #E64D2E;
    display: flex;
    justify-content: space-between;
    color: #fff;
    align-items: center;

    .back {
        font-size: 20rem;
        margin-left: 15rem;
    }

    .title {
        font-size: 18rem;
    }

    .home {
        font-size: 14rem;
        margin-right: 15rem;
    }
}

.directory-detail {
    .item {
        width: 345rem;
        height: 45rem;
        padding: 0 15rem;
        border-bottom: 1rem dotted #998d80;
        background-color: #FAF7F5;
        line-height: 45rem;
        font-size: 14rem;
        overflow: hidden;
    }
}
</style>